//
//  LoginVM.swift
//  MakeCoordinator
//
//  Created by 姚晓俊 on 2019/1/7.
//  Copyright © 2019 姚晓俊. All rights reserved.
//

import UIKit
import RxSwift
class LoginVM: NSObject {
    let textVariable: Variable<String?> = Variable(nil)
    let textObservable: Observable<String>
    
    let tipsObservable: Observable<Bool> //true is hidden
    let maxObservable: Observable<Bool>  //true is hidden
    let hiddenObservable: Observable<Bool>
    
    
    
    override init() {
        textObservable = textVariable.asObservable()
            
            .flatMapLatest({ (str) -> Observable<String> in
                guard let s = str else {
                    return Observable.just("")
                }
                return Observable.just(s)
            }).share(replay: 1)
        
        tipsObservable = textObservable.flatMapLatest{ (str) -> Observable<Bool> in
//            guard let string = str else {
//            return Observable.just(false)
//        }
            if str.count < 4 {
                return Observable.just(false)
            } else {
                return Observable.just(true)
            }
            }.share(replay: 1)
        
        maxObservable = textObservable.flatMapLatest{ str -> Observable<Bool> in
//            guard let string = str else {
//                return Observable.just(true)
//            }
            if str.count > 8 {
                return Observable.just(false)
            } else {
                return Observable.just(true)
            }
            }.share(replay: 1)
        
        hiddenObservable = textObservable.flatMapLatest{ str -> Observable<Bool> in
//            guard let string = str else {
//                return Observable.just(true)
//            }
            if str.count > 8 || str.count < 4{
                return Observable.just(true)
            } else {
                return Observable.just(true)
            }
            }.share(replay: 1)
        
        
        
        super.init()
        
    }
    
    
}
